//
// GPSMapEdit
// (c) Konstantin Galichsky (kg@geopainting.com), 2002-2005
//
// Scale ruler drawing.
//

# include "StdAfx.h"
# include "Ruler.h"
# include "Map.h"
# include "Scale.h"
# include "fast_floor.h"
# include "DrawHelpers.h"
# include "Globals.h"

void ShowRuler (HDC _hDC, int _x0, int _y0) {
	{
		CCritSec::CLock lock (g_cs);

		if (g_map.rectBound.Invalid ())
			return;
	}

	char strText [20];
	const float fRulerLen = GetScale (g_fScale, strText);

	// Draw the ruler background.
	::SelectObject (_hDC, g_hpenWhiteThick);
	::SetROP2 (_hDC, R2_COPYPEN);
	size_t c;
	for (c = 0; c < 4; ++ c) {
		::MoveToEx (_hDC, _x0 + fast_floor (.5f + fRulerLen*c),       _y0 - 5, NULL);
		::LineTo   (_hDC, _x0 + fast_floor (.5f + fRulerLen*c),       _y0);
		::LineTo   (_hDC, _x0 + fast_floor (.5f + fRulerLen*(c + 1)), _y0);
		::LineTo   (_hDC, _x0 + fast_floor (.5f + fRulerLen*(c + 1)), _y0 - 5);
	}

	// Draw the ruler foreground.
	::SelectObject (_hDC, g_hpenBlackThin);
	for (c = 0; c < 4; ++ c) {
		::MoveToEx (_hDC, _x0 + fast_floor (.5f + fRulerLen*c),       _y0 - 5, NULL);
		::LineTo   (_hDC, _x0 + fast_floor (.5f + fRulerLen*c),       _y0);
		::LineTo   (_hDC, _x0 + fast_floor (.5f + fRulerLen*(c + 1)), _y0);
		::LineTo   (_hDC, _x0 + fast_floor (.5f + fRulerLen*(c + 1)), _y0 - 5);
	}

	// Draw the ruler text.
	::SelectObject (_hDC, g_hFont);
	::SetBkMode (_hDC, TRANSPARENT);
	::SetTextAlign (_hDC, TA_BOTTOM | TA_CENTER);
	DrawText2 (_hDC, _x0 + fast_floor (fRulerLen/2), _y0 + 2, strText, c_colBlack);
}

